package com.zuoyi.sqlSession;

import com.zuoyi.config.XMLConfigBuilder;
import com.zuoyi.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * Author: zuo
 * Date: 2021/3/11 18:46
 * Describe:
 */
public class SqlSessionFactoryBuilder {
    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        //通过dom4j技术 解析配置文件
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);

        //生产SqlSessionFactory
        DefaultSqlSessionFactory defaultSqlSessionFactory =
                new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;
    }
}
